/**
 * http://localhost:8083/proj 取得项目根路径
 */
function getRootPath() {
	// 获取当前网址，如： http://localhost:8083/proj/meun.jsp
	var curWwwPath = window.document.location.href;
	// 获取主机地址之后的目录，如： proj/meun.jsp
	var pathName = window.document.location.pathname;
	var pos = curWwwPath.indexOf(pathName);
	// 获取主机地址，如： http://localhost:8083
	var localhostPath = curWwwPath.substring(0, pos);
	// 获取带"/"的项目名，如：/proj
	var projectName = pathName
			.substring(0, pathName.substr(1).indexOf('/') + 1);
	return (localhostPath + projectName);
}

/**
 * 查询收获人信息列表数据
 */
$(function() {
	var currentPage = 1;
	ptlist(currentPage);
});

function ptlist(currentPage) {
	$
			.ajax({
				type : 'post',
				url : getRootPath() + "/DeliveryIn/DeliveryList.do",
				data : {
					"currentPage" : currentPage,
					"userId" : 'U00001'
				},
				async : 'true',
				dataType : 'json',
				success : function(data) {
					var rec = data.page;
					// alert(rec.list[1].productTypeName);
					var html = "";
					for (i = 0; i < rec.list.length; i++) {
						html += "<tr>";
						html += "<td style='padding-top: 18px;'><input type='checkbox' id='ck-all' name='ck-all'/></td>";
						html += "<td style='padding-top: 18px;'>"
								+ rec.list[i].id + "</td>";
						html += "<td style='padding-top: 18px;'>"
								+ rec.list[i].userId + "</td>";
						html += "<td style='padding-top: 18px;'>"
								+ rec.list[i].userName + "</td>";
						html += "<td style='padding-top: 18px;'>"
								+ rec.list[i].phone + "</td>";
						html += "<td style='padding-top: 18px;'>"
								+ rec.list[i].address + "</td>";
						html += "<td style='padding-top: 18px;'>"
								+ rec.list[i].status + "</td>";
						html += "</tr>";
					}

					$("#data_list").html(html);
					// 鼠标经过td的时候就显示td内容
					jQuery(function() {
						// 使用class选择器;例如:list对象->tbody->td对象.
						$("#data_list td").each(function(i) {
							// 给td设置title属性,并且设置td的完整值.给title属性.
							$(this).attr("title", $(this).text());

						});
					});
					var pager = data.page;
					$(".pag_in").html(
							G.getPager(pager.totalRecords, pager.currentPage,
									10, 10, 'ptlist'));
				}

			});
}

/**
 * 模糊查找
 */
function search(currentPage) {
	var keyWord = $("#searchForm :input[id=keyword]").val();

	$
			.ajax({
				type : 'post',
				url : getRootPath() + "/DeliveryIn/DeliveryList.do",
				data : {
					"currentPage" : currentPage,
					"userId" : 'U00001',
					"status" : '',
					"keyWord" : keyWord
				},
				async : 'true',
				dataType : 'json',
				success : function(data) {
					var rec = data.page;
					// alert(rec.list[1].productTypeName);
					var html = "";
					for (i = 0; i < rec.list.length; i++) {
						html += "<tr>";
						html += "<td style='padding-top: 18px;'><input type='checkbox' id='ck-all' name='ck-all'/></td>";
						html += "<td style='padding-top: 18px;'>"
								+ rec.list[i].id + "</td>";
						html += "<td style='padding-top: 18px;'>"
								+ rec.list[i].userId + "</td>";
						html += "<td style='padding-top: 18px;'>"
								+ rec.list[i].userName + "</td>";
						html += "<td style='padding-top: 18px;'>"
								+ rec.list[i].phone + "</td>";
						html += "<td style='padding-top: 18px;'>"
								+ rec.list[i].address + "</td>";
						html += "<td style='padding-top: 18px;'>"
								+ rec.list[i].status + "</td>";
						html += "</tr>";
					}
					$("#data_list").html(html);
					var pager = data.page;
					$(".pag_in").html(
							G.getPager(pager.totalRecords, pager.currentPage,
									10, 10, 'search'));
				}
			});
}